package com.cyf.db.mapper;

import com.cyf.db.bean.Car;
import com.cyf.db.bean.LocalCar;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface CarMapper {

	@Select("select * from local_car where license = #{plate} and parkingId = #{parkingId} and status = 1 and statusbit = 1 limit 0,1")
	Car getByPlateAndParkingId(@Param("plate") String plate, @Param("parkingId") Integer parkingId);


	@Select("select * from local_car where license = #{plate} and status = 1 and statusbit = 1")
	List<Car> getByPlate(@Param("plate") String plate);

	@Select("select c.id, c.license, c.parkingId, p.name parkingName,c.personId " +
			"from local_car c, parking p " +
			"where c.status = 1 and c.statusbit = 1 and c.parkingId = p.id " +
			"and c.license = #{plate} ")
	List<Car> getCarAndParkingInfoByPlate(@Param("plate") String plate);

	@Select("select GROUP_CONCAT(license) from local_car " +
			"where status = 1 and statusbit = 1 " +
			"and personId = #{personId} and parkingId = #{parkingId} ")
	String listPlateByPersonIdAndParkingId(@Param("personId") int personId, @Param("parkingId") Integer parkingId);

	@Select("select * from local_car " +
			"where status = 1 and statusbit = 1 " +
			"and personId = #{personId} and parkingId = #{parkingId} ")
	List<Car> getByPersonIdAndParkingId(@Param("personId") Integer personId, @Param("parkingId") Integer parkingId);

	@Select("SELECT license from local_car " +
			"where personId = #{localPersonId} and parkingId = #{parkingId} " +
			"and `status` = 1 and statusbit = 1")
	List<String> getPlateByPersonIdAndParkingId(@Param("localPersonId") Integer localPersonId,
												 @Param("parkingId") Integer parkingId);

	@Select("select id, localCarId from local_car " +
			"where parkingId = #{parkingId} and personId = #{localPersonId}")
	List<LocalCar> listIdAndLocalIdByPersonId(@Param("parkingId") Integer parkingId,
											  @Param("localPersonId") Integer localPersonId);


	@Update("update local_car set status = 0, statusbit = 0 " +
			"where id = #{id}")
	void delete(@Param("id") Integer id);

	@Select("select * from local_car " +
			"where personId = #{localPersonId} and parkingId = #{parkingId} " +
			"and `status` = 1 and statusbit = 1")
	List<LocalCar> listByPersonIdAndParkingId(@Param("localPersonId") Integer localPersonId,
											  @Param("parkingId") Integer parkingId);


}
